<?php

namespace think\addons;

/**
 * 插件中间件
 */
class Middleware
{
    public function handle($request, \Closure $next)
    {
    	$rule = $request->rule();
    	$route = $rule->getRoute();
    	if (is_string($route)) {
    		list($controller,$actionName) = explode('/',$route);
    		if (str_starts_with($controller,'addons\\') && class_exists($controller)) {
		    	$request
		    	    ->setController($controller)
		    	    ->setAction($actionName);
    		}
    	}
        $response = $next($request);
        return $response;
    }
}